home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Network / Remote / Remote Quit < prev    next >
Encoding:
Text File  |  1999-03-04  |  5.1 KB  |  208 lines  |  [TEXT/ToyS]

  1. (*
  2. V1.02 ◊ This script is PD 1998 by AKUA interactive media AG.
  3.  
  4. Drag items from remote machines onto this script to tell them to 
  5.  quit.
  6.  
  7. V1.02 - Use new KeyChain routines.
  8. V1.01 - Use new gossip functionality.
  9. V1.0 - Start
  10. *)
  11.  
  12.  
  13. -- User setable properties
  14. property kasAllowAlerts : true -- Set to false to stop any alerts from appearing
  15. property kasServerAlerts : true -- Set to false to stop warnings about missed servers
  16. property kasFinder : "Finder" -- name of application to open RemoteLaunchers
  17. property kasAppendage : " ->" -- Appended to file name if we can't use original
  18.  
  19. -- Internal/User setable globals
  20. property kasLinkNeed : false
  21. property kasLinkUserDft : "CasaVision" -- Our friend on all machines
  22. property kasLinkPassDft : "" -- Our friend's password on all machines
  23.  
  24. global gasLinkSet -- Has the friend been looked up?
  25. global gasLinkUser -- Used to connect (KeyChain Lookup)
  26. global gasLinkPass
  27.  
  28. -- Internal globals
  29. global gasOurZone -- Set to zone of gasOurAlias
  30. global gasOurServer -- Set to server of gasOurAlias
  31. global gasOurVol -- Name of volume alias resides on
  32. global gasOurAlias -- The alias we own
  33. global gasOurName -- Name of original alias
  34.  
  35.  
  36. on open fsObjs
  37.     set gasLinkSet to false
  38.     
  39.     repeat with fsObj in fsObjs
  40.         OpenOne(fsObj)
  41.     end repeat
  42. end open
  43.  
  44.  
  45. on OpenOne(fsObj)
  46.     set aInfo to alias info from fsObj
  47.     
  48.     set gasOurZone to alias zone of aInfo
  49.     set gasOurServer to alias server of aInfo
  50.     set gasOurVol to alias volume of aInfo
  51.     GetFriend(false)
  52.     
  53.     RemoteOpen(fsObj)
  54. end OpenOne
  55.  
  56.  
  57. on RemoteOpen(fileAlias)
  58.     talk as user gasLinkUser ¬
  59.         with password gasLinkPass ¬
  60.         on server gasOurServer ¬
  61.         in AppleTalk zone gasOurZone
  62.     
  63.     set myApp to (original name of (alias info from fileAlias))
  64.     
  65.     try
  66.         -- Don't wait for a response, assume the aliases are correct
  67.         tell application myApp of machine gasOurServer ¬
  68.             of zone gasOurZone to quit
  69.     on error err
  70.         if (kasServerAlerts) then
  71.             ShowConnectAlert(myApp, err)
  72.         else
  73.             beep
  74.         end if
  75.     end try
  76. end RemoteOpen
  77.  
  78.  
  79. on GetFriend(override) -- Should later use some modifier key to override?!?
  80.     GetOneFriend(override)
  81. end GetFriend
  82.  
  83.  
  84. on GetOneFriend(override)
  85.     set isLink to true -- Only linking in this script!
  86.     set userMode to "linking"
  87.     set passButtons to {"Cancel", "OK"}
  88.     set passButton to 2
  89.     
  90.     if (gasLinkSet) then
  91.         set defUser to gasLinkUser
  92.         set defPass to gasLinkPass
  93.     else
  94.         set defUser to kasLinkUserDft
  95.         set defPass to kasLinkPassDft
  96.     end if
  97.     
  98.     set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
  99.     
  100.     if (override or usrPwd is {}) then
  101.         set chosen to display dialog ¬
  102.             "Enter the friendly " & userMode & ¬
  103.             " user's name…" default answer defUser ¬
  104.             default button 2 with icon note
  105.         
  106.         if (the button returned of chosen is "OK") then
  107.             set defUser to the text returned of chosen
  108.         else
  109.             return
  110.         end if
  111.         
  112.         set chosen to display dialog ¬
  113.             "Enter the friendly " & userMode & ¬
  114.             " user's password…" buttons passButtons ¬
  115.             default answer defPass default button passButton with icon note
  116.         
  117.         if (the button returned of chosen is not "Cancel") then
  118.             set defPass to the text returned of chosen
  119.         else
  120.             return
  121.         end if
  122.         
  123.         -- Save encrypted user/pass for future access
  124.         KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "")
  125.     else
  126.         set defUser to item 1 of usrPwd
  127.         set defPass to item 2 of usrPwd
  128.     end if
  129.     
  130.     set gasLinkSet to true
  131.     set gasLinkUser to defUser
  132.     set gasLinkPass to defPass
  133. end GetOneFriend
  134.  
  135.  
  136. on PutAwayVol(volName)
  137.     -- Volume
  138.     try
  139.         tell application "Finder" to put away item named volName
  140.     on error
  141.         beep
  142.     end try
  143. end PutAwayVol
  144.  
  145.  
  146. on IsVolMounted(volName)
  147.     -- Volume
  148.     try
  149.         set x to (volName & ":") as alias
  150.         return true
  151.     on error
  152.         return false
  153.     end try
  154. end IsVolMounted
  155.  
  156.  
  157. on ShowMountAlert()
  158.     ShowServerAlert("Couldn't mount volume " & gasOurVol & ¬
  159.         " from " & gasOurServer ¬
  160.         & " in zone " & gasOurZone)
  161. end ShowMountAlert
  162.  
  163.  
  164. on ShowConnectAlert(appName, msg)
  165.     ShowServerAlert("Couldn't connect to " & appName & " on " & ¬
  166.         gasOurServer & " in zone " & gasOurZone & return & return & ¬
  167.         "(" & msg & ")")
  168. end ShowConnectAlert
  169.  
  170.  
  171. on ShowServerAlert(msg)
  172.     set choice to ¬
  173.         display dialog msg buttons {"Reenter Password", "OK"} ¬
  174.             default button 2 with icon stop
  175.     
  176.     if (button returned of choice is not "OK") then GetFriend(true)
  177. end ShowServerAlert
  178.  
  179.  
  180. property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this
  181. property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences>
  182.  
  183. on KeyChainLookUp(zoneName, serverName, isLinking)
  184.     set prefOwner to "πSRV"
  185.     if (isLinking) then set prefOwner to "πLNK"
  186.     
  187.     try
  188.         set myKeyData to load preference named (zoneName & ":" & serverName) ¬
  189.             of type prefOwner in file named kasPrefsFileName
  190.     on error
  191.         return {}
  192.     end try
  193.     
  194.     return (encrypt the data myKeyData with password kasKeyChainPassword)
  195. end KeyChainLookUp
  196.  
  197.  
  198. on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd)
  199.     set myKey to encrypt the data {usr, pwd, ntPwd} with password kasKeyChainPassword
  200.     
  201.     set prefOwner to "πSRV"
  202.     if (isLinking) then set prefOwner to "πLNK"
  203.     
  204.     save preference myKey named (zoneName & ":" & serverName) ¬
  205.         of type prefOwner ¬
  206.         in file named kasPrefsFileName
  207. end KeyChainSave
  208.